package com.yyfax.ph.home;

import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.infrastructure.network.entity.EmptyEntity;
import com.yyfax.ph.base.YJPH;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

import java.util.ArrayList;
import java.util.List;

/**
 * M: 广告通知轮播
 * Created by ying_he on 2017/12/6.<br>
 * Copyright  2017 www.yylending.com. All Rights Reserved.<br><br>
 */

public class AdNoticeModel extends Model<BaseResultEntity> {
	private static final String TAG = AdNoticeModel.class.getSimpleName();

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		AdNoticeModel.Service service = (AdNoticeModel.Service) NetworkHelper.createService(AdNoticeModel.Service.class);
		String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
		return service.getAdNotice(token, (EmptyEntity) params);
	}

	@Override
	public void onNext(BaseResultEntity entity) {
		AdNoticeModel.AdNoticeResult adInfo = cast(entity);
		EventAgent.post(adInfo);
	}

	public interface Service {
		@POST("sys/notice/news")
		Observable<AdNoticeModel.AdNoticeResult> getAdNotice(@Header("token") String token, @Body EmptyEntity params);

	}

	public static class AdNoticeResult extends BaseResultEntity<AdNoticeBean>{}

	public static class AdNoticeBean{
		public List<String> news = new ArrayList<>();
	}
}
